<%@ page import="java.text.DateFormat,
                 java.text.SimpleDateFormat"%>
 <%--
 *  File:   ProdPriceInfo.jsp
 *  Desc:	ProdPriceInfo
 *
 *  Date		         Author		      Changes
 *  2006-3-15	  rogerwang		  Created
 *  2011-1-13	  		Jamesli		  	Modified
 *
 *  Copyright (C) 2000 - 2011 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%
		//init param
  	String privilegeCode = "10203";
	String strModuleName = "PCM";  	
  	String contextPath = request.getContextPath();
%>
<%@ include file="/inc/CommonHeader.inc" %>

<html>
<head>
<title>ProdPriceInfo</title>
<PageFlow:CheckPageFlow pageName="p_prodpriceinfo"/>
<%
    boolean bIsView = false;
    if ("view".equalsIgnoreCase(displayflag)){
        bIsView = true;
    }
    Vector totalsummary = (Vector)pageContext.getAttribute("totalsummary");
        if (totalsummary == null){
            totalsummary = new Vector();
        }
%>
<%@ include file="/inc/CatchError.inc" %>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/Calendar.js"></script>
<!--  script language="JavaScript" src="<%=contextPath%>/js/FuncLib.js"></script-->
  

<script language="JavaScript">
function page_back()
{
  //parent.location.href="ProdMgmtFrm.jsp?<%= OvalTools.randomURL() %>";
  parent.up.page_goback();
}
function clickRow(id,stat)
{
  cform.productpriceid.value = id;
  cform.status.value = stat;
}

function page_delete()
{

  <%if(totalsummary.size()>1){%>
  var tridx= document.cform.tridx.value;
     if(tridx< <%=JspHelper.filterNull(totalsummary.size()-1)%>)
     {
        alert("<%= message.getMessageDesc("CANNOT_DEL_MID_PERIOD") %>");
        return;
     }
  <%}%>
  var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE_TO_DEL") %>");
  if(!flag)
    return;
  document.cform.target="_self";
  document.cform.actionname.value="delete";
  //isRunning=true;
  //document.cform.submit();
  __submitData('cformid',true);
}

function page_add()
{
    if(!checkALLElems(document.getElementById("newdetail"))) return;
     if(add_item())
    {
    	cform.productpriceid.value = "";
        cform.actionname.value = "add";
        cform.target = "_self";
        //isRunning = true;
        //cform.submit();
        __submitData('cformid',true);
    }
}

function page_save()
{
    //if(!checkALLElems(document.getElementById("olddetail"))) return;
     if(save_item())
    {
        cform.actionname.value = "save";
        cform.target = "_self";
        //isRunning = true;
        //cform.submit();
        __submitData('cformid',true);
    }
}



function page_update()
{
    var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE_TO_UPDATE") %>");
    if(!flag)
  return;
    document.cform.actionname.value = "sync";
    document.cform.target="_self";
     isRunning = true;
     document.cform.submit();
}

function save_item()
{        var rowslength= cform.numrows.value;
         for(var i =0 ; i<rowslength;i++){
                   var   startDate  = eval("cform.startdate"+i);
                   var   endDate = eval("cform.enddate"+i);
                   //var dataid =   eval("cform.dataid"+i);
                   //if(dataid.value == -1){
                   // dataid.value = " ";
                   //}
                   if(i==0   && isEmpty(startDate.value) ){
                                             continue;
                   }else  if(i==rowslength-1 &&  isEmpty(endDate.value)){
                                            continue;
                   }
                   else{
                             if(isEmpty(endDate.value)  ||   isEmpty(startDate.value) ){
                                       alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_Date",false) )%>");
                                       return false;
                             }
                             var  endvalue =dateCheck(endDate.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');
                             var  startvalue =dateCheck(startDate.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');
                             if(endvalue<0 || startvalue<0)
                             {
                                       alert("<%= message.getMessageDesc("VALUE_MUST_BE_DATE",label.getLabelName("L_Date",false) )%>");
                                       return false;
                             }
                             if(endvalue<startvalue) {
                                    alert("<%= message.getMessageDesc("STARTDATE_CAN_NOT_LATE_THAN_ENDDATE")%>");
                                    return false;
                            }

                 }
          }
          for(var i =0 ; i<rowslength;i++){
                   var   startDate  = eval("cform.startdate"+i);
                   var   endDate = eval("cform.enddate"+i);
                   //var   lastUpDate = eval("cform.datelastupdated"+i);
                  endDate.value  =dateCheck(endDate.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');
                  startDate.value =dateCheck(startDate.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');
                  <%--lastUpDate.value =dateCheck(lastUpDate.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');--%>
         }
          <%--cform.datelastupdated.value =  dateCheck(cform.datelastupdated.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');--%>
          return   true ;
}
 function  add_item()
 {
           if(isEmpty(cform.startdate.value) &&
              isEmpty(cform.enddate.value))
            {

                       alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_StartTime",false)+","+label.getLabelName("L_EndTime",false) )%>");
                         return false;

            }

            if(isEmpty(cform.startdate.value))
            {
                      var  value =dateCheck(cform.enddate.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');
                       if(value<0){
                                alert("<%= message.getMessageDesc("VALUE_MUST_BE_DATE",label.getLabelName("L_EndTime",false) )%>");
                                return false;
                       }
                      cform.enddate.value =  value;
             }
             else  if(isEmpty(cform.enddate.value))
             {
                    var  value =dateCheck(cform.startdate.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');
                    if(value<0){
                                alert("<%= message.getMessageDesc("VALUE_MUST_BE_DATE",label.getLabelName("L_StartTime",false) )%>");
                                return false;
                     }
                     cform.startdate.value =  value;

            }
           else{
                    var  endvalue =dateCheck(cform.enddate.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');
                    var  startvalue =dateCheck(cform.startdate.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');
                     if(startvalue<0){
                                alert("<%= message.getMessageDesc("VALUE_MUST_BE_DATE",label.getLabelName("L_StartTime",false) )%>");
                                return false;
                       }
                       if(endvalue<0){
                                alert("<%= message.getMessageDesc("VALUE_MUST_BE_DATE",label.getLabelName("L_EndTime",false) )%>");
                                return false;
                       }
                       if(endvalue<startvalue) {
                                    alert("<%= message.getMessageDesc("STARTDATE_CAN_NOT_LATE_THAN_ENDDATE")%>");
                                    return false;
                       }
                       cform.enddate.value =  endvalue;
                       cform.startdate.value =  startvalue;
             }
             <%--cform.datelastupdated.value =  dateCheck(cform.datelastupdated.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>');--%>
             <%--if( isEmpty(cform.datastr.value)  )
              {
                            alert("<%= message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_Data",false) )%>");
                            return false;

              }
             --%>
          return true ;
 }

function page_selectLine(idx)
{
    document.cform.tridx.value = idx;
   //  alert(idx);
}

function page_radiotrue(names){
	obj=eval("document.forms[1]."+ names);
	obj.checked=true;
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form id="cformid" name="cform" method="post" action="<%=contextPath%>/Dispatcher">
    <input type="hidden" name="pagename" value="p_prodpriceinfo">
    <input type="hidden" name="actionname">
    <custom:hidden property="prodid"/>
    <custom:hidden property="productpriceid"/>
    <custom:hidden property="status"/>
    <custom:hidden property="tridx"/>
    <input type="hidden" name="numrows"   value="<%=JspHelper.filterNull(totalsummary.size())%>">



    <table border=0 cellpadding=0 cellspacing=0 width="100%">
  <tr>
    <td valign=top>
      <table border=0 cellpadding=1 cellspacing=0 width="100%">
        <tbody>
        <tr>
          <td bgcolor=#000000 style="PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; PADDING-TOP: 0px">
            <table bgcolor=#000000 border=0 cellpadding=0 cellspacing=0 width="100%">
              <tr>
                <td  bgcolor=#ffffff style="PADDING-BOTTOM: 3px; PADDING-LEFT: 3px; PADDING-RIGHT: 3px; PADDING-TOP: 3px" valign="top">
                  <div id=div2 style="HEIGHT: 415px; OVERFLOW: auto">
                    <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="1">

<%--    top function buttons    --%>
<%--                      <tr>--%>
<%--                        <td colspan="4" class="td_right" height="18"> --%>
<%--                          <a onclick="page_save()"><custom:button type="2" label="L_Save" imgsrc="save_btn.gif" border="0" /></a>--%>
<%--                        </td>--%>
<%--                      </tr>--%>
<% if(!isView){%>
                       <tr>
                        <td colspan="9" class="td_right">
                          <a onclick="page_add();"><custom:button type="2" label="L_Add" imgsrc="add_btn.gif" border="0"/></a>
                          <%if(totalsummary.size() > 0){%>
                          <a onclick="page_delete();"><custom:button type="2" label="L_Delete" imgsrc="delete_btn.gif" border="0"/></a>
                          <a onclick="page_save()"><custom:button type="2" label="L_Save" imgsrc="save_btn.gif" border="0"/></a>
                          <%-- 
                          <a onclick="page_update()"><custom:button type="2" label="L_UpdateFormalData" imgsrc="save_btn.gif" border="0"/></a>
                          --%>
                          <%}%>
                        </td>
                      </tr>
<%}%>
                       <tr class="deepblue-left">
                            <td width="22" class="title_center">&nbsp;</td>
                            <td class="title_center">
                              <%= label.getLabelName("L_StartTime") %><font color="red">*</font>
                            </td>
                            <td class="title_center">
                                <%= label.getLabelName("L_EndTime") %><font color="red">*</font>
                            </td>
                       		<td class="title_center">
                                <%= label.getLabelName("L_ExWorksPrice") %>
                            </td>
                            <td class="title_center">
                                <%= label.getLabelName("L_PurPrice") %>
                            </td>
                            <td class="title_center">
                               <%= label.getLabelName("L_SellingPrice") %>
                            </td> 
                            <td class="title_center">
                               <%= label.getLabelName("L_AssessmentPrice") %>
                            </td>
                       <%-- 
                            <td class="title_center">
                               <%= label.getLabelName("L_NTSFactor") %><font color="red">*</font>
                            </td>
                            <td class="title_center">
                               <%= label.getLabelName("L_ActivityStatus") %>
                            </td>
                       --%>
                        </tr>
<%--    main trs    --%>
<span id="olddetail" >
                <logic:iterate id="onerow" collection="<%= totalsummary%>"  indexId="idx">
                      <%
                        HashMap curHash=(HashMap) onerow;

                        String  strClassType = "";
                        if(idx.intValue()%2 == 0){
                            strClassType = "td-listrom";
                        }
                        else{
                            strClassType = "none";
                        }

                    %>
                       <tr  onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%=JspHelper.filterNull( strClassType )%>'" onClick="page_radiotrue('ids<%=JspHelper.filterNull( idx.intValue())%>');javascript:clickRow(<custom:write name="onerow" property="productpriceid" />,<custom:write name="onerow" property="status" />);page_selectLine(<%=JspHelper.filterNull(idx.intValue())%>);" class="<%=JspHelper.filterNull( strClassType )%>">


                        <td width="22">
                               <input <%=JspHelper.filterNull(idx.intValue()==0?"checked":"")%> id="ids<%=JspHelper.filterNull( idx.intValue())%>" type="radio" name="prodprice" value="<custom:write name="onerow" property="productpriceid" />" class="normalradio" >
                                <script language="javascript">
                                    document.cform.tridx.value = 0;
                                </script>
                        </td>

                        <td >
                            <custom:text name="onerow" property="startdate" colIndex="<%=idx%>" dataType="date"  dataFormatName="dateformat" size="15" command="notnull" label="L_StartTime" style="border:0" readonly="true" onfocus="c.show(this,'cform.startdate','yyyy-MM-dd')"/>

                        </td>
                        <td >
                          <custom:text name="onerow" property="enddate"  colIndex="<%=idx%>" dataType="date" dataFormatName="dateformat" size="15" command="notnull" label="L_EndTime" readonly="true"  style="border:0" onfocus="c.show(this,'cform.enddate','yyyy-MM-dd')"/>
                        
                           </td>          
                        <td>
                            <custom:text name="onerow" property="factoryprice" colIndex="<%=idx%>" size="10" dataType="number"  dataFormatName="priceformat" command="notnull" label="L_ExWorksPrice" />
                            <custom:hidden name="onerow" changedName="factorypriceo" property="factoryprice" colIndex="<%=idx%>"  dataType="number"  dataFormatName="priceformat" command="notnull" label="L_ExWorksPrice" />
                        </td>
                        <td>
                            <custom:text name="onerow" property="untaxtradeprice" colIndex="<%=idx%>" size="10" dataType="number" dataFormatName="priceformat" command="notnull" label="L_PurPrice" />
                            <custom:hidden name="onerow" changedName="untaxtradepriceo" property="untaxtradeprice" colIndex="<%=idx%>"  dataType="number" dataFormatName="priceformat" command="notnull" label="L_PurPrice" />
                        </td>
                        <td>
                            <custom:text name="onerow" property="listprice" colIndex="<%=idx%>" size="10" dataType="number" dataFormatName="priceformat" command="notnull" label="L_SellingPrice"/>
                            <custom:hidden name="onerow" changedName="listpriceo" property="listprice" colIndex="<%=idx%>"  dataType="number" dataFormatName="priceformat" command="notnull" label="L_SellingPrice"/>
                        </td>
                        <td>
                            <custom:text name="onerow" property="ntsprice" colIndex="<%=idx%>" size="10" dataType="number" dataFormatName="priceformat" command="notnull" label="L_AssessmentPrice"/>
                            <custom:hidden name="onerow" changedName="ntspriceo" property="ntsprice" colIndex="<%=idx%>"  dataType="number" dataFormatName="priceformat" command="notnull" label="L_AssessmentPrice"/>
                        </td>
                    <%--
                        <td>
                            <custom:text name="onerow" property="ntsfactor" colIndex="<%=idx%>" size="10" dataType="number" command="notnull" label="L_NTSFactor" />
                            <custom:hidden name="onerow" changedName="ntsfactoro" property="ntsfactor" colIndex="<%=idx%>"  dataType="number" command="notnull" label="L_NTSFactor" />
                        </td>
                        <td>
                            <custom:hidden name="onerow" property="status" colIndex="<%=idx%>"/>
                            <custom:write name="onerow" property="statusname" nbsp="true"/>--%>
                            <custom:hidden name="onerow" property="productpriceid" colIndex="<%=idx%>"/>
                        <%-- </td>
                     --%>
                     </tr>
                    </logic:iterate>
</span>
<% if(!isView){%>
 <span id="newdetail" >
                        <tr>

                            <td width="22">&nbsp;</td>

                            <td >
                            <%
                            	
                            %>
                            <%if(totalsummary.size()==0){%>
                                <custom:text property="startdate" dataType="date"  dataFormatName="dateformat" size="15" command="notnull" onfocus="c.show(this,'cform.startdate','yyyy-MM-dd')" label="L_StartTime"/>
                                 
                            <%}else{%>
                                <%
                                    HashMap lastHash = (HashMap)totalsummary.get(totalsummary.size()-1);
                                    Date lastEndDate = new Date();
                                    if(lastHash==null){
                                        lastHash = new HashMap();
                                    }
                                    if(lastHash.get("enddate")!=null){
                                        lastEndDate = (Date) lastHash.get("enddate");

                                    }

                                    Calendar c1 = Calendar.getInstance();
                                    c1.setTime(lastEndDate);
                                    c1.add(Calendar.DATE, 1);
                                    java.sql.Date newStartDate = new java.sql.Date(c1.getTime().getTime());
                                    pageContext.setAttribute("newstartdate",newStartDate);
                                %>
                                <custom:text property="newstartdate" changedName="startdate" dataType="date"  dataFormatName="dateformat" size="15" command="notnull" label="L_StartTime" onfocus="c.show(this,'cform.startdate','yyyy-MM-dd')"  style="border:0" readonly="true"/>
                                 
                                <script language="javascript">
                                       var lastEndDate = cform.enddate<%=JspHelper.filterNull(totalsummary.size()-1)%>;

                                </script>
                            <%}%>
                            </td>   
                            <td >
                                <custom:text property="enddate" dataType="date" dataFormatName="dateformat" size="15" command="notnull" label="L_EndTime" onfocus="c.show(this,'cform.enddate','yyyy-MM-dd')" />
                                 
                            </td>
                           <td>
                                <custom:text property="factoryprice" size="10" dataType="number" dataFormatName="priceformat" command="notnull" label="L_ExWorksPrice" />
                            </td>
                            <td>
                                <custom:text property="untaxtradeprice" size="10" dataType="number" dataFormatName="priceformat" command="notnull" label="L_WholeSalePriceWithoutTax"/>
                            </td>
                            <td>
                                <custom:text property="listprice" size="10" dataType="number" dataFormatName="priceformat" command="notnull" label="L_Listprice"/>
                            </td>
                            <td>
                                <custom:text property="ntsprice" size="10" dataType="number" dataFormatName="priceformat" command="notnull" label="L_UnitPrice"/>
                            </td>
                        <%--
                            <td>
                                <custom:text property="ntsfactor" size="10" dataType="number" command="notnull" label="L_NTSFactor"/>
                            </td>
                            <td>&nbsp;</td>
						--%>
                          </tr>
</span>
<%}%>
                    </table>

                  </div>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        </tbody>
      </table>
    </td>
  </tr>
  <tr> 
    <td class="summary_top"></td>
  </tr>
  <tr> 
    <td class="td_center">
      <a onclick="page_back()"><custom:button type="1" label="L_Back" imgsrc="back.gif" border="0" style="width:60"/></a>
    </td>
  </tr>
</table>

</form>
</body>
</html>
<%if(totalsummary.size()>0){%>
<script language="javascript">
cform.productpriceid.value=cform.productpriceid0.value;
</script>
<%}%>
